package org.zoomdev.zoom.dao.adapters.mapper;

import org.zoomdev.zoom.dao.Record;
import org.zoomdev.zoom.dao.adapters.ResultSetAdapter;
import org.zoomdev.zoom.dao.adapters.ResultSetMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class RecordMapper implements ResultSetMapper<Record> {

    private final String name;

    private final ResultSetAdapter adapter;

    public RecordMapper(String name, ResultSetAdapter adapter) {
        this.name = name;
        this.adapter = adapter;
    }


    @Override
    public void map(ResultSet rs, int columnIndex, Record data) throws SQLException {
        Object value = adapter.getObject(rs, columnIndex);
        data.put(name, value);
    }
}
